import Flutter
import UIKit
//import Reachability

public class SwiftFlunetPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "flunet", binaryMessenger: registrar.messenger())
    let instance = SwiftFlunetPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }
    
    public override init() {
        super.init();
        let reachability = try! Reachability()

        reachability.whenReachable = { reachability in
            if reachability.connection == .wifi {
                print("Reachable via WiFi")
            } else {
                print("Reachable via Cellular")
            }
        }
        reachability.whenUnreachable = { _ in
            print("Not reachable")
        }

        do {
            try reachability.startNotifier()
        } catch {
            print("Unable to start notifier")
        }
    }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    
    switch call.method {
    case "status":
        result(1);
        break;
    default:
        result("iOS 0" + UIDevice.current.systemVersion);
        break;
    }
    
  }
}
